package example;

import javax.swing.JOptionPane;

public class TestException {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String numberStringInput = JOptionPane
				.showInputDialog("Enter a number:");
		try {
			String numberString = getValue(numberStringInput);
			System.out.println(Integer.parseInt(numberString));
		} catch (InvalidStringException e) {
			System.out.println(e);
		} catch (InvalidPointException e) {
			System.out.println(e);
		}
	}

	public static String getValue(String str) throws InvalidStringException,
			InvalidPointException {
		for (int i = 0; i < str.length(); i++) {
			if (Character.isLetter(str.charAt(i))) {
				throw new InvalidStringException(str.charAt(i));
			} else if (str.charAt(i) == '.')
				throw new InvalidPointException(str.charAt(i));
		}
		return str;
	}
}

@SuppressWarnings("serial")
class InvalidStringException extends Exception {
	private char ch;

	public InvalidStringException(char ch) {
		this.ch = ch;
	}

	public char getCh() {
		return ch;
	}

	public String toString() {
		return ch + " is an invalid value!";
	}
}

@SuppressWarnings("serial")
class InvalidPointException extends Exception {
	private char ch;

	public InvalidPointException(char ch) {
		this.ch = ch;
	}

	public char getCh() {
		return ch;
	}

	public String toString() {
		return " \'.\'is an invalid value!";
	}
}
